package com.yh.patterns.combination.demo1;

/**
 * @Auther:云尚学Java
 * 容器构件
 */

import java.util.ArrayList;

public class Branch extends Component {

    private ArrayList<Component>list;
    private String name;

    public Branch(String name) {
        this.name = name;
    }
    public void receiveDoc() {
        System.out.println(name+"收到文件");
    }
    public Component getChild(int n) {
        return list.get(n);
    }
    public void add(Component abBranch) {
        list.add(abBranch);
    }
    public void remove(Component abBranch) {
        list.remove(abBranch);
    }
    public String getName() {
        return name;
    }
    public void sendDoc(Component abBranch) {
        System.out.println(name+ "发送文件到"+abBranch.getName());
        abBranch.receiveDoc();
    }
}

